﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace yule.Model.Sys
{
    /// <summary>
    /// 地区
    /// </summary>
    [DataContract]
    [Serializable]
    public class Region : yule.Model.Base.Sys.Region, ITree<yule.Model.Sys.Region>
    {

        public new dynamic ParentId
        {
            get { return base.ParentId; }
            set { base.ParentId = value; }
        }

        /// <summary>
        /// 保存ID一直
        /// </summary>
        public new string Code
        {
            get
            {
                return base.Id;
            }
            set
            {
                base.Id = value;
            }
        }

        public Region Parent
        {
            get
            {
                return Region.Select(this.ParentId);
            }
        }

        public IList<Region> Childs
        {
            get
            {
                return yule.Common.ServiceManager.ServiceContext.CreateService<yule.IDAL.Sys.IRegion>().GetChilds(this);
            }
        }

        public int Level
        {
            get { return TreeHelper.GetLevel<yule.Model.Sys.Region>(this); }
        }

    }
}